/**
 *    加密,解密方法
 *
 */
 let crypto = require('crypto');
 /**
  * 加密解密方式
  */
 let algorithm = 'aes-256-cbc';
 
 let key = '9815c9e69268bc2fc2085c1lc6q75a42';
 let charset = 'utf8';
 let cipherEncoding = 'base64';
 let iv = '9183296589LSCQEG';
 
 
 let encrypt = function (plaintext) {
     //加密
   let cipher = crypto.createCipheriv(algorithm, key, iv);
   let cipherChunks = [];
     cipherChunks.push(cipher.update(plaintext, charset, cipherEncoding));
     cipherChunks.push(cipher.final(cipherEncoding));
   let encrypt = cipherChunks.join('');
     encrypt = encrypt.replace(/\+/g, '%2b');
     return encrypt;
 };
 
 let decrypt = function (encrypttext) {
     encrypttext = encrypttext.replace(/(%2b)/g, '+');
     //解密start
   let decipher = crypto.createDecipheriv(algorithm, key, iv);
   let plainChunks = [];
     plainChunks.push(decipher.update(encrypttext, cipherEncoding, charset));
     plainChunks.push(decipher.final(charset));
     return plainChunks.join('');
 }
 
 
 let encryptStr = encrypt('bbbb');
 
 let decryptStr = decrypt(encryptStr);
 
 console.log('加' + encryptStr);
 console.log('解' + decryptStr);
